package com.hjqjl.puke.ui;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.hjqjl.puke.BaseActivity;
import com.hjqjl.puke.R;
import com.hjqjl.puke.util.GlideUtils;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * h --- 2017/11/10.
 */

public class PukeAllShowActivity extends BaseActivity {
    @BindView(R.id.rl_puke_allshow)
    RecyclerView rlPukeAllshow;

    ArrayList<Integer> pukeList;

    @Override
    protected int getLayoutView() {
        return R.layout.activity_pukeallshow;
    }

    @Override
    protected void initData() {
        pukeList = getIntent().getIntegerArrayListExtra("list");

        rlPukeAllshow.setLayoutManager(new GridLayoutManager(mContext, 4));
        //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
//        rlPukeAllshow.setHasFixedSize(true);
        //创建并设置Adapter
        MyAdapter mAdapter = new MyAdapter(pukeList);
        rlPukeAllshow.setAdapter(mAdapter);
    }

    @Override
    protected void processLogic() {

    }

    private class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
        public ArrayList<Integer> datas = null;

        public MyAdapter(ArrayList<Integer> datas) {
            this.datas = datas;
        }

        //创建新View，被LayoutManager所调用
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_pukeallshow, viewGroup, false);
            ViewHolder vh = new ViewHolder(view);
            return vh;
        }

        //将数据与界面进行绑定的操作
        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int position) {
            GlideUtils.loadImg(mContext, datas.get(position), viewHolder.mImageView);
        }

        //获取数据的数量
        @Override
        public int getItemCount() {
            return datas.size();
        }

        //自定义的ViewHolder，持有每个Item的的所有界面元素
        public class ViewHolder extends RecyclerView.ViewHolder {
            public ImageView mImageView;

            public ViewHolder(View view) {
                super(view);
                mImageView = (ImageView) view.findViewById(R.id.iv_pukeallshow_item);
            }
        }
    }
}
